package com.hu.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hu.common.annotation.Log;
import com.hu.common.core.controller.BaseController;
import com.hu.common.core.domain.AjaxResult;
import com.hu.common.enums.BusinessType;
import com.hu.system.domain.StockInbound;
import com.hu.system.service.IStockInboundService;
import com.hu.common.utils.poi.ExcelUtil;
import com.hu.common.core.page.TableDataInfo;

/**
 * 库存入库Controller
 *
 * @author hu
 * @date 2025-01-21
 */
@RestController
@RequestMapping("/business/stock/inbound")
public class StockInboundController extends BaseController {
    @Autowired
    private IStockInboundService stockInboundService;

    /**
     * 查询库存入库列表
     */
    @PreAuthorize("@ss.hasPermi('stock:inbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockInbound stockInbound) {
        startPage();
        List<StockInbound> list = stockInboundService.selectStockInboundList(stockInbound);
        return getDataTable(list);
    }

    /**
     * 导出库存入库列表
     */
    @PreAuthorize("@ss.hasPermi('stock:inbound:export')")
    @Log(title = "库存入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockInbound stockInbound) {
        List<StockInbound> list = stockInboundService.selectStockInboundList(stockInbound);
        ExcelUtil<StockInbound> util = new ExcelUtil<StockInbound>(StockInbound.class);
        util.exportExcel(response, list, "库存入库数据");
    }

    /**
     * 获取库存入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:inbound:query')")
    @GetMapping(value = "/{inboundId}")
    public AjaxResult getInfo(@PathVariable("inboundId") Long inboundId) {
        StockInbound inbound = stockInboundService.selectStockInboundByInboundId(inboundId);
        if (inbound == null) {
            return error("您没有权限查看该入库记录或记录不存在");
        }
        return success(inbound);
    }
}

